package com.xqiapp.jsp.web;

import com.xqiapp.bean.Resultx;
import com.xqiapp.jsp.config.WebxException;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.Map;

/**
 * Created by rwrwd7 on 2017/9/21.
 *
 *
 * 我也不知道为什么要通过命令打包以后，使用java -jar 才能正确的运行。wtf
 *
 *
 */
@Controller
public class HomeController {

    @Value("${application.message:Hello World}")
    private String message = "Hello World";

    @GetMapping(value = {"","/","/home"})
    public String welcome(Map<String, Object> model) {
        model.put("time", new Date());
        model.put("message", this.message);
        return "home";
    }

    @GetMapping("/error")
    @ResponseBody
    public Resultx handleException() {
        return new Resultx("Some data I want to send back to the client.").status(false);
    }


//    @ExceptionHandler(WebxException.class)
//    @ResponseStatus(HttpStatus.BAD_REQUEST)
//    @ResponseBody
//    public Resultx handleMyRuntimeException(WebxException exception) {
//        return new Resultx("Some data I want to send back to the client.").status(false);
//    }
}
